home *** CD-ROM | disk | FTP | other *** search
/ BMUG Revelations / BMUG Revelations.toast / Programming / Programming Languages / Yerk 3.64 / Supplement / my stuff / late bind example < prev    next >
Text File  |  1991-01-01  |  1KB  |  50 lines

  1. \ suppose you have an array with object addresses stored in it:
  2.  
  3. 4 array objectArray
  4.  
  5. \ make three objects
  6.  
  7. var myVar
  8. int myInt
  9. rect myRect
  10. string myString
  11. new: myString
  12.  
  13. myVar myInt myRect myString put: objectArray
  14.  
  15. \ now put a few values in the objects
  16.  
  17. 12 put: myVar
  18. 10 put: myInt
  19. 10 10 100 100 put: myRect
  20. " hello" put: myString
  21.  
  22. \ now draw each object, but late bind to the objects held in the array: 
  23.  
  24.     print: [ 0 at: objectArray ]
  25.     print: [ 1 at: objectArray ]
  26.     print: [ 2 at: objectArray ]
  27.     print: [ 3 at: objectArray ]
  28.  
  29. \ or do it like this
  30.  
  31. : printStuff limit: objectArray 0 DO print: [ i at: objectArray ] LOOP ;
  32.  
  33. printStuff
  34.  
  35. \ suppose myVar points to another object like myRect
  36.  
  37. myRect put: myVar
  38.  
  39. print: [ obj: myVar ]    \ is the same as
  40. print: [ get: myVar ]
  41.  
  42.  
  43. \ note: printstuff will send the print: message to each object in the 
  44. \    objectArray. Since myVar now holds an object itself, to print the
  45. \    second object (in this case myRect), one must do this:
  46.  
  47. \ print: [ obj: [ 0 at: objectArray ] ]
  48.  
  49.  
  50.